package net.lanelife.casino.cms.web.controller;

import java.util.List;

import javax.servlet.ServletRequest;

import net.lanelife.casino.caipiao.dto.admin.ActivityConfigCreateDTO;
import net.lanelife.casino.caipiao.dto.admin.ActivityConfigDTO;
import net.lanelife.casino.caipiao.dto.admin.ActivityConfigTable;
import net.lanelife.casino.caipiao.dto.admin.ActivityConfigUpdateDTO;
import net.lanelife.casino.caipiao.entity.ActivityConfig;
import net.lanelife.casino.caipiao.service.api.IActivityConfigService;
import net.lanelife.casino.caipiao.service.api.IActivityService;
import net.lanelife.casino.cms.web.controller.support.CRUDController;
import net.lanelife.casino.common.repository.SearchFilter;
import net.lanelife.casino.common.service.support.IGenericService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping(value = ActivityConfigController.PATH)
public class ActivityConfigController extends CRUDController<ActivityConfig, Integer, ActivityConfigDTO, ActivityConfigCreateDTO, ActivityConfigUpdateDTO, ActivityConfigTable<ActivityConfigDTO>> {
	
	public static final String PATH = "/activity-config";
	
	public ActivityConfigController() {
		super(PATH);
	}
	
	@Autowired
	private IActivityConfigService activityConfigService;

	@Autowired
	private IActivityService activityService;
	
	@Override
	protected IGenericService<ActivityConfig, Integer> getService() {
		return activityConfigService;
	}
	
	@Override
	protected void preList(Model model, ServletRequest request) throws Exception {
		model.addAttribute("activity", activityService.find(Integer.valueOf(request.getParameter("activityId"))));
	}

	@Override
	protected void postList(Model model, Pageable pageable, ServletRequest request, List<SearchFilter> filters) throws Exception {
		filters.add(new SearchFilter("activityId", SearchFilter.Operator.EQ, Integer.valueOf(request.getParameter("activityId"))));
	}
	
}
